package com.moleq.adapter;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import com.moleq.adapter.ReportAdapter.ViewHolder;
import com.moleq.logic.TransactionManager;
import com.moleq.models.PosEJ;
import com.moleq.models.PosTender;
import com.moleq.models.PosTrns;
import com.moleq.models.TenderSignature;
import com.moleq.mgpos.activities.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.text.format.DateFormat;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.moleq.service.PosTenderService;
import com.moleq.service.ServiceManager;
import com.moleq.util.ImageUtil;
import com.moleq.util.MoleQUtil;

public class ShowViewSignatureAdpater extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<String[]> Source;
	private Context context;
	private int selectedRow = 0;
	private ViewHolder holder = null;
	PosTenderService mPosTenderService = null;
	
	public ShowViewSignatureAdpater(Context context, List<String[]> Source) {
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		this.Source = Source;
		mPosTenderService = new PosTenderService(context);
	}

	public void setSource(List<String[]> Source) {
		this.Source = Source;
	}

	public int getCount() {
		return Source.size();
	}

	public Object getItem(int position) {
		return Source.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.viewsignature, null);
			holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
			holder.tv_foot = (TextView) convertView.findViewById(R.id.tv_foot);
			holder.imgv_signature = (ImageView) convertView.findViewById(R.id.imgv_signature);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tv_content.setText(Source.get(position)[0]);
		holder.imgv_signature.setImageBitmap(ImageUtil.stringtoBitmap(Source.get(position)[1]));
		holder.tv_foot.setText(MoleQUtil.parsePrintContent(TransactionManager.getInstance().getViewCreditFoot()));
		

		return convertView;
	}

	public final class ViewHolder {
		public TextView tv_content;
		public TextView tv_foot;
		
		public ImageView imgv_signature;
	}

	public void ScrollToRow(int row) {
		selectedRow = row;
		this.notifyDataSetChanged();
	}

	public int GetSelectedIndex() {
		return selectedRow;
	}
}
